//
//  MWBannerProView.m
//  Weshare
//
//  Created by Mike on 16/8/10.
//  Copyright © 2016年 wxwl. All rights reserved.
//

#import "MWBannerProView.h"

@interface MWBannerProView ()
@property (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) UILabel     *titleLabel;
@property (nonatomic, strong) UILabel     *contentLabel;
@property NSTimer* timer;
@end

@implementation MWBannerProView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.8f;
        [self initUI];
    }
    return self;
}

- (void)show: (UIView*) supView{

    for(UIView* view in [supView subviews])
    {
        if([view isKindOfClass:[MWBannerProView class]])
        {
           [view removeFromSuperview];
        }
    }
    
    [supView addSubview:self];
    
    _contentLabel.text = [HDUtil check:self.notification.alertBody];
    self.top=-60;
    [UIView animateWithDuration:0.5 animations:^{
        self.top = 0;}];
    
    self.timer=[NSTimer scheduledTimerWithTimeInterval:6 block:^{
        [UIView animateWithDuration:0.5 animations:^{
            self.top = -60;} completion:^(BOOL finished) {
               [self removeFromSuperview];
            }];
        
    } repeats:NO];
}

- (void)initUI{
    _logoImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 10, 20, 20)];
    _logoImage.image = [UIImage imageNamed:@"share_icon"];
    _logoImage.layer.cornerRadius = 4.0f;
    [self addSubview:_logoImage];
    
    _titleLabel = [self creatLabel:CGRectMake(44, 13, SCREEN_WIDTH - 56, 15)];
    _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    _titleLabel.text = @"我享度假";
     [self addSubview:_titleLabel];
    
    _contentLabel = [self creatLabel:CGRectMake(44, 38, SCREEN_WIDTH - 56, 15)];
    _contentLabel.font = HeitiFont(14);
    [self addSubview:_contentLabel];

     UIButton * clickBtn = [[UIButton alloc] initWithFrame:self.bounds];
     clickBtn.backgroundColor = [UIColor clearColor];
    [clickBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview: clickBtn];
}

- (void)click
{
    [self.timer invalidate];
    self.timer=nil;
    
    [self removeFromSuperview];
    if ([self.delegate respondsToSelector:@selector(notificationTapAction:)]) {
        [self.delegate notificationTapAction:self.notification];
    }
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.textColor = [UIColor whiteColor];
    return label;
}

@end
